<?php

/*

  Treasure	$4

  Worth $1
  While this is in play, when you buy a card costing $4 or less that is not a Victory card, gain a copy of it.

 */

class Talisman extends Card implements iTreasure, iKingdom, iProsperity, iReactingCard {

    private $reactConditions;

    public function __construct() {
        parent::__construct("Talisman", 4);
        $this->value = new Price(1);
        $this->undoPlay = true;
        $this->undoBuy = true;

        $this->reactConditions = new ReactionConditions();
        $this->reactConditions->action = array(Buy);
        $this->reactConditions->actor = array(Yourself);
        $this->reactConditions->cardLocation = array(PlayArea);
        $this->reactConditions->limit = ForEachCard;
        $this->reactConditions->isMandatory = true;
    }

    public function getDescription() {
        return array(
            "Worth $1",
            "While this is in play, when you buy a card costing $4 or less that is not a Victory card, gain a copy of it.");
    }
    
    public function autoPlayNum(Game $game) {
        return -1;
    }

    public function getConditions() {
        return $this->reactConditions;
    }

    public function isReactRelevant(Game $game, $card, $name) {
        $price = $card->getPrice($game);
        $fourPrice = new Price(4);
        if (!$card instanceof iVictory && $price->compare($fourPrice) <= 0) {
            return true;
        }
        return false;
    }

    public function react(Game $game, $card, $name) {
        ScreenDisplay::addScreenMessage($game, true, "activate " . nicePrint($this), "activates " . nicePrint($this), $name);
        $price = $card->getPrice($game);
        $fourPrice = new Price(4);
        if (!$card instanceof iVictory && $price->compare($fourPrice) <= 0) {
            $card = $game->moveCardFromPileToPile($card, BoardCards, DiscardPile, $name);
            ScreenDisplay::addScreenMessage($game, true, "gain " . nicePrint($card), "gains " . ScreenDisplay::$LMSG, $name);
        }
        $game->setTempCard($card);
        return true;
    }

}

?>